<?php

class Location_model extends CI_Model {

    function LocationModel() {
        parent::Model();
    }

    function get_province() {
        $this->db->order_by("`name`", "ASC");
        $query = $this->db->get('Province');
//        $query = $this->db->get_where('Province')->order_by('`name`', 'DESC');
        return $query->result_array();
    }

    function get_district($province_ID) {
        $this->db->where('province_ID', $province_ID);
        $this->db->order_by("`order`", "ASC");
        $query = $this->db->get('District');
        return $query->result_array();
    }

    function get_commune($district_ID) {
        $this->db->where('district_ID', $district_ID);
        $this->db->order_by("`order`", "ASC");
        $query = $this->db->get('Commune');
        return $query->result_array();
    }

    function get_village($commune_ID) {
        $this->db->where('commune_ID', $commune_ID);
        $this->db->order_by("`order`", "ASC");
        $query = $this->db->get('Village');
        return $query->result_array();
    }

    function checkExistingOfficialNumber($officialNumberToCheck) {
        $query = $this->db->get_where('Province')->order_by('name', 'DESC');
        if (!$query->num_rows) {
            $this->db->insert('Officer', array(
                'function_ID' => check_post('status'),
                'name' => check_post('name'),
                'note' => check_post('note')
            ));
            combine_session('success', 'Added new officer successfully.');
        }
    }

}

?>